package work.xiaohong.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.xiaohong.storage.dao.StorageTblMapper;
import work.xiaohong.storage.entity.StorageTbl;
import work.xiaohong.storage.service.StorageTblService;

import java.util.List;

@SuppressWarnings("all")
@Service
public class StorageTblServiceImpl implements StorageTblService {

    @Autowired
    private StorageTblMapper storageTblMapper;


    /**
     * 条件+分页查询StorageTbl
     * @param storageTbl 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<StorageTbl> findPage(StorageTbl storageTbl, int page, int size){
        // 构建查询条件
        QueryWrapper<StorageTbl> queryWrapper = new QueryWrapper<StorageTbl>(storageTbl);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return storageTblMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询StorageTbl
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<StorageTbl> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return storageTblMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法StorageTbl
     * @param storageTbl
     * @return
     */
    @Override
    public List<StorageTbl> findList(StorageTbl storageTbl){
        // 构建查询条件
        QueryWrapper<StorageTbl> queryWrapper = new QueryWrapper<StorageTbl>(storageTbl);
        // 查询数据
        return storageTblMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除StorageTbl
     * @param id
     */
    @Override
    public void delete(Integer id){
        storageTblMapper.deleteById(id);
    }

    /**
     * 根据Id批量删除StorageTbl数据
     * @param id
     */
    @Override
    public void deleteByIds(List<Long> asList){
        storageTblMapper.deleteBatchIds(asList);
    }


    /**
     * 根据ID修改StorageTbl
     * @param storageTbl
     */
    @Override
    public void updateById(StorageTbl storageTbl){
        // 初始化一些不可修改数据
        storageTblMapper.updateById(storageTbl);
    }

    /**
     * 增加StorageTbl
     * @param storageTbl
     */
    @Override
    public void add(StorageTbl storageTbl){
        storageTblMapper.insert(storageTbl);
    }

    /**
     * 根据ID查询StorageTbl
     * @param id
     * @return
     */
    @Override
    public StorageTbl findById(Integer id){
        return  storageTblMapper.selectById(id);
    }

    /**
     * 查询全部StorageTbl数据
     * @return
     */
    @Override
    public List<StorageTbl> findAll() {
        return storageTblMapper.selectList(null);
    }
}
